
Date.prototype.pattern=function(fmt) {
  var o = {
    "M+" : this.getMonth()+1,
    "d+" : this.getDate(),
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12,
    "H+" : this.getHours(),
    "m+" : this.getMinutes(),
    "s+" : this.getSeconds(),
    "q+" : Math.floor((this.getMonth()+3)/3),
    "S" : this.getMilliseconds()
  };
  var week = {
    "0" : "\u65e5",
    "1" : "\u4e00",
    "2" : "\u4e8c",
    "3" : "\u4e09",
    "4" : "\u56db",
    "5" : "\u4e94",
    "6" : "\u516d"
  };
  if(/(y+)/.test(fmt)){
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  }
  if(/(E+)/.test(fmt)){
    fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);
  }
  for(var k in o){
    if(new RegExp("("+ k +")").test(fmt)){
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    }
  }
  return fmt;
}

function toggleLeft() {
  var left   = $('#left');
  var middle = $('#middle');
  var right  = $('#right');
  if (left.css('margin-left').substring(0,1)=='-') {
    left.css({'margin-left':'0px'});
    right.css({'left':'196px'});
    middle.hide();
  }
  else {
    left.css({'margin-left':'-'+(left.width()+24)+'px'});
    right.css({'left':'52px'});
    middle.show();
  }
}

function initHeight() {
  var l = $('#left');
  var m = $('#middle');
  var r = $('#right');
  var d = document.documentElement;
	var h = (window.innerHeight || self.innerHeight || (d&&d.clientHeight) || document.body.clientHeight) - 100;
  l.css({'height':h+'px'});
  m.css({'height':h+'px'});
  r.css({'height':h+'px'});
  
  var h1 = 0;
  var h2 = 0;
  if ($('#navAlert').is(':visible')) {
    h1 = $('#navAlert').height() + 28;
  }
  if ($('#navTool').is(':visible')) {
    h2 = $('#navTool').height() + 28;
  }
  $('#main').css({'height':(h-34-h1-h2)+'px'});
  $('#rightFrame').css({'height':(h-36-h1-h2)+'px'});
}

function initMenu() {
  $('#menu li').css({'text-indent':'1em'});
  $('#menu ul li').css({'text-indent':'2em'});
  $('#menu ul ul li').css({'text-indent':'3em'});
  $('#menu ul ul ul li').css({'text-indent':'4em'});
  $('#menu ul').hide();
  $('#menu li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        $('#menu span').removeClass();
        checkElement.slideUp('normal');
        return false;
      }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        if (checkElement.prev().parent().parent().attr('id') == 'menu') {
          $('#menu ul').slideUp('normal');          
        }
        $('#menu span').removeClass();
        if (checkElement.prev().prev().is('span')) {
          checkElement.prev().prev().addClass('collapse');
        }
        checkElement.slideDown('normal');
        return false;
      }
      if ($(this).attr('href')=='#') {
        return false;
      }
      
      var tabcss = $(this).attr('rel');
      if (tabcss && tabcss!='') {
        $('#navTabName').addClass(tabcss);
      }
      else {
        $('#navTabName').removeClass();
      }
      $('#menu li').removeClass('selected');
      $(this).parent().addClass('selected');
      $(this).attr('target','rightFrame');
      $('#navTabName').html($(this).html());
    }
  );
}

function setNavTabName(name) {
  $('#navTabName').html(name);
}

function showTime() {
  var date = new Date();  
  $('#showtime').text(date.pattern("yyyy-MM-dd EEE hh:mm:ss"));
  setTimeout(showTime,1000);
}

function tableColor(table) {
  $('#'+table+' tr').click(function() {
    $('#'+table+' tr').each(function(){
      if($(this).hasClass("highlight")){
        $(this).removeClass("highlight");
      }
    });
    $(this).addClass("highlight");
  }); 
}

function showDiv(div) {
  $('#'+div).css('display','block');
}

function hideDiv() {
  $('#'+div).css('display','none');
}

function showImg(showdiv) {
  
}

function initUpload() {
  swfu = new SWFUpload({
    upload_url: "",
    file_post_name: "Filedata",

    file_size_limit : "2 MB",
    file_types : "*.jpg;*.gif;*.png",
    file_types_description : "All Files",
    file_upload_limit : 0,
    file_queue_limit : 0,
          
    button_image_url : "",
    button_placeholder_id : "spanButtonPlaceholder",
    button_width: 65,
    button_height: 22,
          
    file_dialog_start_handler: fileDialogStart,
    file_queued_handler : fileQueued,
    file_queue_error_handler : fileQueueError,
    file_dialog_complete_handler : fileDialogComplete,
          
    swfupload_preload_handler : preLoad,
    swfupload_load_failed_handler : loadFailed,
    upload_progress_handler : uploadProgress,
    upload_error_handler : uploadError,
    upload_success_handler : uploadSuccess,
    upload_complete_handler : uploadComplete,

    flash_url : "",

    custom_settings : {},
    debug: false
  });
}

function toJsonString(json){
  var S = [];
  for(var i in json){
    json[i] = typeof json[i] == 'string' ? '"'+json[i]+'"' : (typeof json[i] == 'object' ? toJsonString(json[i]) : json[i]);
    S.push('"'+i+'":'+json[i]);
  }
  return '{'+S.join(',')+'}';
}

